package com.sskj.postar.controller;

import com.sskj.postar.core.ret.HttpResponse;
import com.sskj.postar.core.ret.HttpResult;
import com.sskj.postar.model.UserAssetRecord;
import com.sskj.postar.service.UserAssetRecordService;
import com.sskj.postar.service.UserAssetService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private UserAssetRecordService userAssetRecordService;
    @Resource
    private UserAssetService userAssetService;

    /**
     * 充值
     * @param assetType 资产类型
     * @param address 地址
     * @param id 充值用户id
     * @param number 充值数量
     * @return
     */
    @PostMapping("/recharge")
    public HttpResult recharge(String assetType, String address, int id, String number){
        UserAssetRecord userAssetRecord = new UserAssetRecord();
        userAssetRecord.setType(0);
        userAssetRecord.setAddress(address);
        userAssetRecord.setNumber(number);
        userAssetRecord.setUserId(id);
        userAssetRecord.setStatus(1);
        userAssetRecord.setSubmitTime(new Date());
        userAssetRecord.setCheckTime(new Date());
        userAssetRecord.setAssetType(assetType);
        userAssetRecordService.insert(userAssetRecord);
        userAssetService.updateMoney(id,assetType,number,"0");
        return HttpResponse.makeOKRsp("充值成功",null);

    }
}
